# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-fuubar
pkgver=2.5.1
pkgrel=1
pkgdesc='The instafailing RSpec progress bar formatter'
arch=(any)
url='https://github.com/thekompanee/fuubar'
license=(MIT)
depends=(ruby-rspec-core ruby-ruby-progressbar)
checkdepends=(ruby-rspec)
options=(!emptydirs)
source=(https://github.com/thekompanee/fuubar/archive/releases/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('0188e92c6b8582c3bad9de2d8584d46c47b3ed3550648e9b591149605b6d4b06')

prepare() {
  cd fuubar-releases-v$pkgver
  sed -e 's/~>/>=/' -e '/signing_key/d' -i fuubar.gemspec
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd fuubar-releases-v$pkgver
  gem build fuubar.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    fuubar-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd fuubar-releases-v$pkgver
  GEM_HOME="tmp_install/$_gemdir" rspec
}

package() {
  cd fuubar-releases-v$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
